⚡ Bolt: Optimize cold start enrichment hot path#12
⚡ Bolt: Optimize cold start enrichment hot path#12lonewolf0708 wants to merge 1 commit intolonewolf0708-patch-10-floodingfrom
Conversation
- Moved `enrichmentMap` and `getColdEnrichment` from `updateTorque` to module scope. - Reduces table and closure allocations in the 2000Hz hot path. - Decreases pressure on the Lua Garbage Collector. Co-authored-by: lonewolf0708 <51030924+lonewolf0708@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: The optimization moves the
enrichmentMaptable and thegetColdEnrichmentfunction from the local scope of theupdateTorquefunction to the module level.🎯 Why:
updateTorqueis a high-frequency physics update loop that runs at 2000Hz. In Lua, defining a table literal or a function closure inside another function results in a new allocation on every call. At 2000Hz, this means 2000 table and 2000 function allocations per second per engine, which causes significant pressure on the Garbage Collector and wastes CPU cycles.📊 Impact: Reduces memory churn by 4000 allocations per second per engine. This leads to fewer GC pauses and lower CPU usage for the physics simulation, particularly in cold environments where this logic is active.
🔬 Measurement: The improvement can be verified by monitoring Lua memory usage and GC activity while the engine is in a cold start state. CPU profiling of the physics thread will also show reduced overhead in the
updateTorquefunction.PR created automatically by Jules for task 16104853658478507756 started by @lonewolf0708